package com.ihrm.common.exception;

import com.ihrm.common.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class BaseExceptionHandler {

    //自定义异常
    @ExceptionHandler(CommonException.class)
    public Result<String> exceptionHandler(CommonException ex) {
        Integer code = ex.getCode();
        String message = ex.getMessage();
        return new Result(code, message, false);
    }

    // 捕获未捕获异常
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception ex){
        ex.printStackTrace();
        log.error("异常信息：{}", ex.getMessage());
        return Result.ERROR();
    }


}